Skip to content

Add support for PostgreSQL Insert table aliases (#1069)#1084

Merged
alamb merged 1 commit intoapache:mainfrom
boydjohnson:fix-insert-alias
Jan 14, 2024
Merged

Add support for PostgreSQL Insert table aliases (#1069)#1084
alamb merged 1 commit intoapache:mainfrom
boydjohnson:fix-insert-alias

Conversation

@boydjohnson
Copy link
Copy Markdown
Contributor

This is a fix for #1069

@coveralls
Copy link
Copy Markdown

coveralls commented Jan 6, 2024

Pull Request Test Coverage Report for Build 7513619314

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.05%) to 87.858%

Totals Coverage Status
Change from base Build 7396929961: 0.05%
Covered Lines: 18828
Relevant Lines: 21430

💛 - Coveralls

Copy link
Copy Markdown
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this contribution @boydjohnson - this is looking close.

Comment thread src/ast/mod.rs Outdated
Comment on lines +2417 to +2422
let table_name = if let Some(Ident {
value,
quote_style: _,
}) = table_alias
{
format!("{table_name} AS {value}")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like we should format the alias using whatever quote style was originally used

Maybe something like

Suggested change
let table_name = if let Some(Ident {
value,
quote_style: _,
}) = table_alias
{
format!("{table_name} AS {value}")
let table_name = if let Some(table_alias) = table_alias
{
format!("{table_name} AS {table_alias}")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I followed your advice. I rebased and force-pushed. I hope that is ok.


pg().verified_stmt(sql1);

let sql2 = "INSERT INTO test_tables AS test_table (id, a) VALUES (DEFAULT, 123)";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please:

  1. Make the sql2 a second test (e.g. test_simple_postgres_insert_with_alias)
  2. Add a test for a quoted identifier, something like INSERT INTO test_tables AS "Test_Table" (id, a) VALUES (DEFAULT, 123), perhaps

Copy link
Copy Markdown
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @boydjohnson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants